package com.dokimall.order.web;

import com.dokimall.order.service.OrderService;
import com.dokimall.order.vo.OrderConfirmVo;
import com.dokimall.order.vo.OrderSubimtVo;
import com.dokimall.order.vo.SumitOrderResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.UUID;
import java.util.concurrent.ExecutionException;

/**
 * @ClassName: orderWebController
 * @Description:
 * @Author
 * @Date 2021/10/26
 * @Version 1.0
 */
@Controller
public class OrderWebController {

    @Autowired
    OrderService orderService;

    @GetMapping("/toTrade")
    public String toTrade(Model model) throws ExecutionException, InterruptedException {

        OrderConfirmVo orderConfirmVo = orderService.confirmOrder();
        model.addAttribute("orderConfirmData",orderConfirmVo);
        //展示订单确认页数据

        return "confirm";
    }

    /***
     *
     * 下单功能
     */

    @PostMapping("/submitOrder")
    public String submitOrder(OrderSubimtVo orderSubimtVo,Model model){
        SumitOrderResponseVo responseVo = orderService.submitOrder(orderSubimtVo);
        if(responseVo.getCode() == 0){
            model.addAttribute("submitOrderResp",responseVo);
            return "pay";
        }else {
            return "redirect:http://order.dokimall.com/toTrade";
        }
    }

}
